using JEngine.Core;
using System;

namespace CL
{
    public interface ICLSingletonReverseDispose
    {

    }

    public abstract class CLASingleton : DisposeObject
    {
        internal abstract void Register();
    }

    public abstract class CLSingleton<T> : CLASingleton where T : CLSingleton<T>
    {
        private bool isDisposed;

        private static T instance;

        public static T Instance
        {
            get
            {
                return instance;
            }
            private set
            {
                instance = value;
            }
        }

        internal override void Register()
        {
            Instance = (T)this;
        }

        public bool IsDisposed()
        {
            return this.isDisposed;
        }

        protected virtual void Destroy()
        {

        }

        public override void Dispose()
        {
            if (this.isDisposed)
            {
                return;
            }

            this.isDisposed = true;

            this.Destroy();

            Instance = null;
        }
    }
}
